package com.szgr.baoyin.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.volley.toolbox.ImageLoader;
import com.szgr.baoyin.MyApplication;
import com.szgr.baoyin.R;
import com.szgr.baoyin.model.ReduceGoods;
import com.szgr.baoyin.utils.Constant;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by yang on 15/9/24.
 */
public class SpecialGridAdapter extends BaseAdapter {
    private Context mContext;
    private final ImageLoader imageLoader;
    private List<ReduceGoods> urls;

    public SpecialGridAdapter(Context context, List<ReduceGoods> specialImageUrls){
        mContext = context;
        imageLoader = MyApplication.getmInstance().getImageLoader();
        urls = specialImageUrls;
    }
    @Override
    public int getCount() {
        return urls.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if(convertView == null){
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_special_today_grid_view,parent,false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }
        holder = (ViewHolder) convertView.getTag();

        ImageLoader.ImageListener listener = ImageLoader.getImageListener(holder.img_head,R.drawable.loading,R.drawable.loading);
        imageLoader.get(Constant.URL_IMAGE + urls.get(position).getGoods_image(), listener);
        return convertView;
    }

    public void setData(ArrayList<ReduceGoods> specialImageUrls) {
        urls = specialImageUrls;
        notifyDataSetChanged();
    }

    private class ViewHolder {
        TextView tv_big;
        TextView tv_small;
        ImageView img_head;

        public ViewHolder(View view){
            tv_big = (TextView) view.findViewById(R.id.special_big_text);
            tv_small = (TextView) view.findViewById(R.id.special_small_text);
            img_head = (ImageView) view.findViewById(R.id.special_image_view);
        }
    }
}
